<template>
	<view class="c-checkbox-group" ref="checkboxRef">
		<slot></slot>
	</view>
</template>

<script setup>
	import { provide, reactive } from 'vue';

	const emits = defineEmits(['update:modelValue']);
	const state = reactive({
		checkedList: []
	});
	function test(data) { 
		if(!data.instance.value) return;
		if (data.status.value) {
			if (!state.checkedList.includes(data.instance.value)) {
				state.checkedList.push(data.instance.value);
				emits('update:modelValue', state.checkedList);
			}
		} else {
			const index = state.checkedList.findIndex((item) => item == data.instance.value);
			state.checkedList.splice(index, 1);
			emits('update:modelValue', state.checkedList);
		}
	}

	provide('parent', test);
</script>

<style></style>